using System.IO;

namespace Google.Protobuf
{
    public static class CodedOutputStreamFactory
    {
        private static CodedOutputStream codedOutputStream = null;
        public static CodedOutputStream Get(byte[] data)
        {
            if (codedOutputStream == null)
            {
                codedOutputStream = new CodedOutputStream(data);
            }
            else
            {
                codedOutputStream.Init(data);
            }

            return codedOutputStream;
        }

        public static CodedOutputStream Get(byte[] data, int length)
        {
            if (codedOutputStream == null)
            {
                codedOutputStream = new CodedOutputStream(data, 0, length);
            }
            else
            {
                codedOutputStream.Init(data, 0, length);
            }

            return codedOutputStream;
        }

        public static CodedOutputStream Get(Stream output)
        {
            if (codedOutputStream == null)
            {
                codedOutputStream = new CodedOutputStream(output);
            }
            else
            {
                codedOutputStream.Init(output);
            }

            return codedOutputStream;
        }
    }
}

